using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.Utils;

using DevExpress.XtraEditors.Repository;

using MM.Entities;
using MM.Business;  
namespace MM
{
    public partial class frmTimPhieuNK_KetQua : Form
    {
        string _matau = "";
        string _nguoitao = "";
        string _sConn = "";

        // the delegate the subscribers must implement
        public delegate void ChonPhieuNhapKho(object frmTimPhieuNK_KetQua, ChonPhieuNKEventArgs chonPNKevent);

        // an instance of the delegate
        public ChonPhieuNhapKho chonPNK;

        public frmTimPhieuNK_KetQua(string sConn, List<PHIEU_NHAP_HANG> lstPNK)
        {
            InitializeComponent();
            _sConn = sConn;

            this.InitGrid(lstPNK);
        }
        private void InitGrid(List<PHIEU_NHAP_HANG> lstPNK)
        {
            this.gridControl1.DataSource = lstPNK;
        }

        private void lnkSoPhieuNK_Click(object sender, EventArgs e)
        {
            ColumnView col = (ColumnView)this.gridControl1.FocusedView;
            string mapnk = col.FocusedValue.ToString();           

            ChonPhieuNKEventArgs pnkevent = new ChonPhieuNKEventArgs(mapnk);

            if (chonPNK != null)
            {
                chonPNK(this, pnkevent);
            }
        }

        private void gridDSVT_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (gridDSVT.FocusedRowHandle >= 0)
                {
                    string mapnk = gridDSVT.GetFocusedRowCellValue("MaPhieuNhapHang").ToString();

                    ChonPhieuNKEventArgs pnkevent = new ChonPhieuNKEventArgs(mapnk);

                    if (chonPNK != null)
                    {
                        chonPNK(this, pnkevent);
                    }
                }
            }
        }
    }

    class ChonPhieuNKEventArgs : EventArgs
    {
        public string MaPhieuNhapKho = "";

        public ChonPhieuNKEventArgs(string mapnk)
        {
            MaPhieuNhapKho = mapnk;
        }
    }
}